package com.fan.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fan.dao.TeacherDao;
import com.fan.entity.Teacher;
import com.fan.service.TeacherService;
import com.sixth.entity.EduTeacher;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @program: self-tui-education
 * @description:
 * @author: 老范
 * @create: 2022-04-18 15:51
 **/
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> implements TeacherService {
    @Autowired
    private TeacherDao teacherDao;
//    @Override
//    public EduTeacher findTeacherName(String teacherName) {
//        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
//        wrapper.eq("name",teacherName);
//        EduTeacher teacher = teacherDao.selectOne(wrapper);
//        return teacher;
//    }

    @Override
    public CommonResult queryAllTeacherBYTeacherName(String teacherName) {
        Teacher teachers = teacherDao.queryAllTeacherBYTeacherName(teacherName);
        return new CommonResult(2000,"成功",teachers);
    }




    @Override
    public CommonResult findTeacherBYMobile(String mobile) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile",mobile);
        Teacher teacher = teacherDao.selectOne(wrapper);
        return new CommonResult(2000,"获取成功",teacher);
    }

    @Override
    public CommonResult findTeacherBYMobiles(String teacherMobile) {
        List<EduTeacher> teacherList=teacherDao.findTeacherBYMobile(teacherMobile);
        return new CommonResult(2000,"查询成功",teacherList);
    }

    @Override
    public CommonResult updateTeacherBYMobile(Teacher teacher) {
        Date date = new Date();
        teacher.setGmtModified(date);
        int i = teacherDao.updateById(teacher);
        if (i>0){
            return new CommonResult(2000,"修改成功",null);
        }else {
            return new CommonResult(5000,"修改失败",null);
        }
    }


}
